package com.rapig.mail.biz;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URL;

public class ConfigBIZ {
	public static String read(String name) {
		String cfgFile = "cfg/" + name;
		URL fileUrl = Thread.currentThread().getContextClassLoader()
				.getResource(cfgFile);
		String path = fileUrl.getPath();

		StringBuffer ret = new StringBuffer();
		File file = new File(path);
		BufferedReader reader = null;
		try {
			reader = new BufferedReader(new FileReader(file));
			String tempString = null;
			while ((tempString = reader.readLine()) != null) {
				ret.append(tempString);
			}
			reader.close();
		} catch (Exception e) {
			e.printStackTrace();
		}

		return ret.toString();
	}

	public static void write(String name, String content) {
		String cfgFile = "cfg/" + name;
		URL fileUrl = Thread.currentThread().getContextClassLoader()
				.getResource(cfgFile);
		String path = fileUrl.getPath();
		try {
			FileWriter writer = new FileWriter(path, false);
			writer.write(content);
			writer.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
